package com.pinyoumei.app.activity.wallet;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.pinyoumei.app.R;
import com.pinyoumei.app.activity.AliPayPasswordActivity;
import com.pinyoumei.app.activity.BackBuyActivity;
import com.pinyoumei.app.activity.BalanceActivity;
import com.pinyoumei.app.activity.BaseActivity;
import com.pinyoumei.app.activity.GroupBuyActivity;
import com.pinyoumei.app.activity.PayPassWordActivity;
import com.pinyoumei.app.activity.ReNameActivity;
import com.pinyoumei.app.activity.WebViewActivity;
import com.pinyoumei.app.bean.BaseBean;
import com.pinyoumei.app.bean.RechargeBean;
import com.pinyoumei.app.bean.RechargeInitBean;
import com.pinyoumei.app.network.Constants;
import com.pinyoumei.app.utils.EventBusUtils;
import com.pinyoumei.app.utils.IntentUtils;
import com.pinyoumei.app.utils.SPUtils;
import com.pinyoumei.app.utils.SignatureUtils;
import com.pinyoumei.app.utils.ToastUtils;
import com.pinyoumei.app.utils.event.WxLoginEvent;
import com.pinyoumei.app.view.WithDrawKeyboard;
import com.pinyoumei.app.view.WithDrawPayEditText;
import com.pinyoumei.app.view.dialog.BottomDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.http.Path;

/**
 * Created by Administrator on 2021-08-16.
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2021-08-16        Administrator             新增Person类
 * 2021-08-16        Administrator             增加sex属性
 * 充值提现
 */
public class RechargeActivity extends BaseActivity implements View.OnClickListener {

    private PopupWindow popupWindow;

    private String[] KEY = new String[]{
            "1", "2", "3",
            "4", "5", "6",
            "7", "8", "9",
            "<<", "0", "完成"
    };
    private WithDrawKeyboard keyboard;
    private WithDrawPayEditText payEditText;
    private EditText edittext_money;
    private TextView tv_select;
    private int pay_type = 1;

    private String we_chat = "";
    private String zfb_desc= "";
    private Button bt_1;
    private String price;
    private TextView tv_user_balance;
    private TextView tv_withdraw_desc;
    private TextView tv_apply_withdraw_amount;
    private TextView tv_total_withdraw_amount;
    private boolean editIng = true;
    private List<BankCardListBean.BankCardListDto> listDtos = null;
    private int listItemClickPostion = 0;
    private BottomDialog bottomDialog = null;
    private String bankName = "default";
    private String bankNo = "default";
    private String bankAcNo = "default";
    private String bankAcName = "default";
    private TextView dsrBackcardAdd,dsrBackcardEdit,tvEdit,tv_bing_zfb,tv_bing_wechat,tv_sure;
    private CheckBox checkbox_zhifubao,checkbox_wechat;
    private BackCardAdapter backCardAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge);
        EventBusUtils.register(this);
        InitWidget();

        InitData(1);
    }


    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onMessageEventMain(WxLoginEvent event) {
        if (!TextUtils.isEmpty(event.openid)) {
            BandWechat(event.openid,event.user_nick_name,event.user_head_img);
            EventBusUtils.removeStickyEvent(WxLoginEvent.class);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, priority = 1)
    public void onMessageEventMain(RechargeBean event) {
        if (event != null ) {

            InitData(1);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, priority = 1)
    public void onMessageEventMain(String deteleBank) {
       if(TextUtils.equals(deteleBank,"bankInfoDelete")){
           pay_type = 1;
           checkbox_zhifubao.setChecked(true);
           checkbox_wechat.setChecked(false);
           tv_select.setText("支付宝");
           if(listDtos != null){
               for (int i=0;i<listDtos.size();i++){
                   listDtos.get(i).setBox(false);
                   backCardAdapter.notifyDataSetChanged();
               }
           }
       }
    }


    private void InitWidget() {
        RelativeLayout relative_finish = findViewById(R.id.relative_finish);
        relative_finish.setOnClickListener(this);
        RelativeLayout rl_select = findViewById(R.id.rl_select);
        rl_select.setOnClickListener(this);
        RelativeLayout rl_recharge = findViewById(R.id.rl_recharge);
        rl_recharge.setOnClickListener(this);
        tv_withdraw_desc = findViewById(R.id.tv_withdraw_desc);
        tv_apply_withdraw_amount = findViewById(R.id.tv_apply_withdraw_amount);
        tv_total_withdraw_amount = findViewById(R.id.tv_total_withdraw_amount);
        tv_select = findViewById(R.id.tv_select);
        tv_user_balance = findViewById(R.id.tv_user_balance);
        edittext_money = findViewById(R.id.edittext_money);

        bt_1 = findViewById(R.id.bt_1);
        bt_1.setOnClickListener(this);
        Button bt_2 = findViewById(R.id.bt_2);
        bt_2.setOnClickListener(this);
        Button bt_3 = findViewById(R.id.bt_3);
        bt_3.setOnClickListener(this);



    }


    private void InitData(int withdraw_type) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(RechargeActivity.this));
        map.put("withdraw_type",withdraw_type);

        OkGo.<String>post(Constants.MY_WITHDRAW)
                .params("user_id", SPUtils.getAppUserId(RechargeActivity.this))
                .params("withdraw_type",withdraw_type)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {



                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }

                    @Override
                    public void onCacheSuccess(Response<String> response) {
                        super.onCacheSuccess(response);
                        setData(response);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        RechargeInitBean rechargeBean = gson.fromJson(response.body(), RechargeInitBean.class);

                        if (rechargeBean.getCode() >= 0) {
                            tv_user_balance.setText(rechargeBean.getResult().getWithdraw_amount()+"");
                            tv_withdraw_desc.setText(rechargeBean.getResult().getWithdraw_desc()+"");
                            tv_apply_withdraw_amount.setText(rechargeBean.getResult().getApply_withdraw_amount()+"");
                            tv_total_withdraw_amount.setText(rechargeBean.getResult().getTotal_withdraw_amount()+"");

                            zfb_desc = rechargeBean.getResult().getAlipay_info();
                            we_chat = rechargeBean.getResult().getWechat_info();

                        } else {
                            Toast.makeText(RechargeActivity.this, rechargeBean.getMsg(), Toast.LENGTH_SHORT).show();
                        }

                    }

                });
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        	case R.id.relative_finish:
        		finish();
        		break;
        		case R.id.rl_recharge:
                    startActivity(new Intent(RechargeActivity.this, BalanceActivity.class));
        		break;
        		case R.id.rl_select:
                    selectSetTv();
        		break;

        		case R.id.bt_1:
                    //申请提现
                    if (!TextUtils.isEmpty(edittext_money.getText().toString().trim())){
                        price = edittext_money.getText().toString().trim();
                        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        boolean isOpen = imm.isActive();
                        if (isOpen) {
                            //第一个参数为需要关闭的Editext
                            // imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);//没有显示则显示
                            imm.hideSoftInputFromWindow(edittext_money.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                        }

                        showPasswordPopupWindow(RechargeActivity.this);
                    }else{
                        Toast.makeText(RechargeActivity.this, "请输入要提现的金额", Toast.LENGTH_SHORT).show();
                    }

        		break;

            case R.id.bt_2:
                //卖货收入提现
                startActivity(new Intent(RechargeActivity.this, GroupBuyActivity.class));
                break;
            case R.id.bt_3:
                //返现佣金提现
                startActivity(new Intent(RechargeActivity.this, BackBuyActivity.class));
                break;

        	default:
        		break;
        }
    }




    //密码输入框弹窗采用PopupWindow方式
    private void showPasswordPopupWindow(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_layout_paypassword, null);
        keyboard = view.findViewById(R.id.Keyboard_pay);
        payEditText = view.findViewById(R.id.pet_business_password);
        TextView textView = view.findViewById(R.id.tv_pay_forget);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(mContext, PayPassWordActivity.class);
                startActivity(i);
            }
        });
        RelativeLayout bt = view.findViewById(R.id.bt_paypassword_close);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        //设置键盘
        keyboard.setKeyboardKeys(KEY);
        //键盘键的点击事件

        keyboard.setOnClickKeyboardListener(new WithDrawKeyboard.OnClickKeyboardListener() {
            @Override
            public void onKeyClick(int position, String value) {
                if (position < 11 && position != 9) {
                    payEditText.add(value);
                } else if (position == 9) {
                    payEditText.remove();
                } else if (position == 11) {
                    if (TextUtils.isEmpty(payEditText.getText())) {
                        ToastUtils.showLong("请输入交易密码。");
                        return;
                    }
//
                }
            }
        });

        //当密码输入完成时的回调
        payEditText.setOnInputFinishedListener(new WithDrawPayEditText.OnInputFinishedListener() {
            @Override
            public void onInputFinished(String password) {
                //提现
                if (popupWindow!=null){
                    popupWindow.dismiss();
                }

                withdrawSubmit( 1, pay_type,price, password);
            }
        });

        popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.update();

        popupWindow.showAtLocation(bt_1, Gravity.BOTTOM, 0, 0);
    }




    private void withdrawSubmit(int withdraw_type,int withdraw_out_type,String withdraw_amount,String withdraw_deal_pwd) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(RechargeActivity.this));
        map.put("withdraw_type",withdraw_type);
        map.put("withdraw_out_type",withdraw_out_type);
        map.put("withdraw_amount",withdraw_amount);
        map.put("withdraw_deal_pwd",withdraw_deal_pwd);
        map.put("bank_ac_no",bankAcNo);
        map.put("bank_ac_name",bankAcName);
        map.put("bank_no",bankNo);
        map.put("bank_name",bankName);

        OkGo.<String>post(Constants.MY_WITHDRAW_SUBMIT)
                .params("user_id", SPUtils.getAppUserId(RechargeActivity.this))
                .params("withdraw_type",withdraw_type)
                .params("withdraw_out_type",withdraw_out_type)
                .params("withdraw_amount",withdraw_amount)
                .params("withdraw_deal_pwd",withdraw_deal_pwd)
                .params("bank_ac_no",bankAcNo)
                .params("bank_ac_name",bankAcName)
                .params("bank_no",bankNo)
                .params("bank_name",bankName)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {



                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }

                    @Override
                    public void onCacheSuccess(Response<String> response) {
                        super.onCacheSuccess(response);
                        setData(response);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        BaseBean rechargeBean = gson.fromJson(response.body(), BaseBean.class);
                        if (rechargeBean.getCode() == -100){
                            Intent intent = new Intent(RechargeActivity.this,PayPassWordActivity.class);
                            startActivity(intent);

                        }else if (rechargeBean.getCode() == -200){
                            Intent intent = new Intent(RechargeActivity.this, ReNameActivity.class);
                            startActivity(intent);
                        }else if (rechargeBean.getCode() >= 0) {
                            Toast.makeText(RechargeActivity.this, rechargeBean.getMsg(), Toast.LENGTH_SHORT).show();
                            InitData(1);
                        } else {
                            Toast.makeText(RechargeActivity.this, rechargeBean.getMsg(), Toast.LENGTH_SHORT).show();
                        }

                    }

                });
    }


    private void BandWechat(String open_id,String user_nick_name,String user_head_img) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(RechargeActivity.this));
        map.put("open_id", open_id);
        map.put("user_nick_name", user_nick_name);
        map.put("user_head_img", user_head_img);

        OkGo.<String>post(Constants.SETTING_WECHAT_BAND)
                .params("user_id", SPUtils.getAppUserId(RechargeActivity.this))
                .params("open_id", open_id)
                .params("user_nick_name", user_nick_name)
                .params("user_head_img", user_head_img)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();

                        BaseBean settingUserBean = gson.fromJson(response.body(), BaseBean.class);

                        if (settingUserBean.getCode() >= 0) {
                            InitData(1);
                            ToastUtils.showShort(settingUserBean.getMsg());
                        } else {
                            ToastUtils.showShort(settingUserBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBusUtils.unregister(this);
    }



    private void selectSetTv(){
        //选择
        pay_type = 1;
        bottomDialog = new BottomDialog(RechargeActivity.this,R.layout.dialog_select_recharge);
        bottomDialog.show();

        tv_bing_zfb =bottomDialog. findViewById(R.id.tv_bing_zfb);
        tv_bing_wechat =bottomDialog. findViewById(R.id.tv_bing_wechat);
        TextView tv_wechat_desc =bottomDialog. findViewById(R.id.tv_wechat_desc);
        tv_wechat_desc.setText(we_chat);
        TextView tv_ali_desc =bottomDialog. findViewById(R.id.tv_ali_desc);
        tv_ali_desc.setText(zfb_desc);
        if (zfb_desc.equals("暂未绑定支付宝")){
            tv_bing_zfb.setVisibility(View.VISIBLE);
            tv_bing_zfb.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bottomDialog.dismiss();
//                    Intent intent = new Intent(RechargeActivity.this, AliPayPasswordActivity.class);;
//                    startActivityForResult(intent,3001);

                    if (!TextUtils.isEmpty(Constants.KF_URL)){
                        final Intent intent = new Intent(RechargeActivity.this, ReNameActivity.class);
                        intent.putExtra("url",Constants.KF_URL);
                        startActivity(intent);
                    }

                }
            });
        }
        if (we_chat.equals("暂未绑定微信")){

            tv_bing_wechat.setVisibility(View.VISIBLE);
            tv_bing_wechat.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bottomDialog.dismiss();
                    IntentUtils.loginWeixin(RechargeActivity.this,"wxfcdbc78aac617cee");
                }
            });
        }

        ImageView image_cancle =bottomDialog. findViewById(R.id.image_cancle);
        tv_sure =bottomDialog. findViewById(R.id.tv_sure);
        RelativeLayout rl_wechat = bottomDialog.findViewById(R.id.rl_wechat);
        RelativeLayout relative_zhifubaopay = bottomDialog.findViewById(R.id.relative_zhifubaopay);
        checkbox_zhifubao = bottomDialog.findViewById(R.id.checkbox_zhifubao);
        checkbox_wechat =bottomDialog. findViewById(R.id.checkbox_wechat);
        switch (pay_type) {
            case 1:
                checkbox_zhifubao.setChecked(true);
                break;
            case 2:
                checkbox_wechat.setChecked(true);
                break;
            default:
                break;
        }

        image_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomDialog.dismiss();
                clickEdit(false);
                editIng = true;
                if(listDtos != null){
                    checkbox_zhifubao.setChecked(true);
                    for (int i=0;i<listDtos.size();i++){
                        listDtos.get(i).setBox(false);
                        backCardAdapter.notifyDataSetChanged();
                    }
                }
            }
        });
        relative_zhifubaopay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pay_type = 1;
                checkbox_zhifubao.setChecked(true);
                checkbox_wechat.setChecked(false);
                if(editIng) {
                    bottomDialog.dismiss();
                    tv_select.setText("支付宝");
                    if(listDtos != null){
                        for (int i=0;i<listDtos.size();i++){
                            listDtos.get(i).setBox(false);
                            backCardAdapter.notifyDataSetChanged();
                        }
                    }
                }

            }
        });
        rl_wechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pay_type = 2;
                checkbox_zhifubao.setChecked(false);
                checkbox_wechat.setChecked(true);
                if(editIng) {
                    bottomDialog.dismiss();
                    tv_select.setText("微信");

                }
            }
        });

        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickEdit(false);
                editIng = true;
                if(listDtos != null){
                    checkbox_zhifubao.setChecked(true);
                    for (int i=0;i<listDtos.size();i++){
                        listDtos.get(i).setBox(false);
                        backCardAdapter.notifyDataSetChanged();
                    }
                }
            }
        });
        bankInfoSave(SPUtils.getAppUserId(this));
    }

    private void addSelectBackCard(BottomDialog dialog){
        ListView dsrBackcardList =dialog. findViewById(R.id.dsr_backcard_list);
        dsrBackcardAdd =dialog. findViewById(R.id.dsr_backcard_add);
        dsrBackcardEdit =dialog. findViewById(R.id.dsr_backcard_edit);
        tvEdit =dialog. findViewById(R.id.tv_edit);
        backCardAdapter = new BackCardAdapter(RechargeActivity.this);
        backCardAdapter.setData(listDtos);
        dsrBackcardList.setAdapter(backCardAdapter);
        backCardAdapter.notifyDataSetChanged();
        setListViewHeight(dsrBackcardList);
        dsrBackcardEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < listDtos.size(); i++) {
                    if (listDtos.get(i).isBox()){
                        bankInfoDelete(listDtos.get(i).getId());
                    }
                }
            }
        });
        dsrBackcardAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(RechargeActivity.this,AddBankCardActivity.class));
            }
        });
        tvEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickEdit(true);
                editIng = false;
                checkbox_zhifubao.setChecked(false);
                checkbox_wechat.setChecked(false);
            }
        });

        dsrBackcardList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                pay_type = 3;
                bankAcNo = listDtos.get(position).getBankAcNo();
                bankAcName = listDtos.get(position).getBankAcName();
                bankNo = listDtos.get(position).getBankCode();
                bankName = listDtos.get(position).getBankName();
                listItemClickPostion = position;
                checkbox_zhifubao.setChecked(false);
                checkbox_wechat.setChecked(false);
                if(listDtos != null){
                    for (int i=0;i<listDtos.size();i++){
                        listDtos.get(i).setBox(false);
                        backCardAdapter.notifyDataSetChanged();
                    }
                }
                listDtos.get(position).setBox(true);
                backCardAdapter.notifyDataSetChanged();
                if(editIng) {
                    dialog.dismiss();
                    tv_select.setText(listDtos.get(position).getBankName());
                }
            }
        });

    }

    private void setListViewHeight(ListView listView){
        ViewGroup.LayoutParams layoutParams = listView.getLayoutParams();
        if(listDtos.size()>=5) {
            layoutParams.height = getResources().getDimensionPixelOffset(R.dimen.dp_260);
        }else{
            layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        }
        listView.setLayoutParams(layoutParams);
    }

    private void clickEdit(boolean isedit){
        if (isedit){
            tvEdit.setVisibility(View.GONE);
            tv_sure.setVisibility(View.VISIBLE);
            dsrBackcardAdd.setVisibility(View.GONE);
            dsrBackcardEdit.setVisibility(View.VISIBLE);
            tv_bing_zfb.setVisibility(View.INVISIBLE);
            tv_bing_wechat.setVisibility(View.INVISIBLE);
            checkbox_wechat.setVisibility(View.INVISIBLE);
            checkbox_zhifubao.setVisibility(View.INVISIBLE);
        }else{
            tvEdit.setVisibility(View.VISIBLE);
            tv_sure.setVisibility(View.GONE);
            dsrBackcardAdd.setVisibility(View.VISIBLE);
            dsrBackcardEdit.setVisibility(View.GONE);
            checkbox_wechat.setVisibility(View.VISIBLE);
            checkbox_zhifubao.setVisibility(View.VISIBLE);
            if (zfb_desc.equals("暂未绑定支付宝")) {
                tv_bing_zfb.setVisibility(View.VISIBLE);
            }
            if (we_chat.equals("暂未绑定支付宝")) {
                tv_bing_wechat.setVisibility(View.VISIBLE);
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onMessageEventMain(List<BankCardListBean.BankCardListDto> bankDto) {
        if (bankDto.size()>0) {
            listDtos.clear();
            listDtos.addAll(bankDto);
            backCardAdapter.notifyDataSetChanged();
        }
    }

    private void bankInfoSave(String user_id){
        Map<String, Object> map = new HashMap<>();
        map.put("userId",user_id);
        OkGo.<String>post(Constants.bankInfolist)
                .params("userId", user_id)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {

                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        loadingDailog.dismiss();
                        BankCardListBean bean = gson.fromJson(response.body(), BankCardListBean.class);
                        listDtos = bean.getResult();
                        addSelectBackCard(bottomDialog);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });
    }

    private void bankInfoDelete(String id){

        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        String url = Constants.bankInfoDelete+id+"?id="+id+"&sign="+SignatureUtils.createSignature(map, Constants.SIGN_SECRET);
        OkGo.<String>get(url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        loadingDailog.dismiss();
                        BaseBean bean = gson.fromJson(response.body(), BaseBean.class);
                        if(bean.getCode() == 1){
                            listDtos.remove(listItemClickPostion);
                            backCardAdapter.notifyDataSetChanged();
                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });
    }




}
